<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>RobotComm: E:/RobotProgram/RobotComm/RobotComm/src/modbustcp_server.h 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">RobotComm
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.17 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_ea3ce016c58d232f7fa1d1ef45b82b3d.html">RobotComm</a></li><li class="navelem"><a class="el" href="dir_2310dfda14d3ad679a5031c36e4d7867.html">RobotComm</a></li><li class="navelem"><a class="el" href="dir_786ca8624b6fa0351b28de730a9f6683.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">modbustcp_server.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="modbustcp__server_8h.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifndef MODBUSTCP_SERVER_H</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define MODBUSTCP_SERVER_H</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#pragma once</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &quot;comm_server.h&quot;</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &quot;mutex.h&quot;</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;queue&gt;</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#include &quot;buffer.h&quot;</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#include &quot;win_event_lock.h&quot;</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#include &quot;plc_standard_class.h&quot;</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="comm__struct__define_8h.html">comm_struct_define.h</a>&quot;</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160; </div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment">//最大数据区大小</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#define MAX_SERVER_DATA_LEN 200</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160; </div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">using namespace </span>plc;</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keyword">using namespace </span>std;</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160; </div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="keyword">namespace </span>el</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;{</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    <span class="keyword">class </span>TcpServer;</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="keyword">class </span>TcpConnect;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    <span class="keyword">class </span>TcpClient;</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;}</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160; </div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160; </div>
<div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="class_modbus_tcp_server.html">   35</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_modbus_tcp_server.html">ModbusTcpServer</a></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;{</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    <a class="code" href="class_modbus_tcp_server.html">ModbusTcpServer</a>(el::CommServer *comm_server_=NULL);</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    ~<a class="code" href="class_modbus_tcp_server.html">ModbusTcpServer</a>();</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    <span class="keywordtype">int</span> Execute();          <span class="comment">//通讯触发主函数</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160; </div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    <span class="comment">//设置通讯配置信息</span></div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    <span class="keywordtype">int</span> setServerInfo(<a class="code" href="struct_s_modbus_tcp_server_info.html">SModbusTcpServerInfo</a> *info);</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    <a class="code" href="struct_s_modbus_tcp_server_info.html">SModbusTcpServerInfo</a> *getServerInfo();</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    vector&lt;STcpConnectClientInfo&gt; getModbusTcpServerConnectList();</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160; </div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    <span class="keywordtype">void</span> onMassage(el::TcpConnect *connect);            <span class="comment">//收到消息回调函数</span></div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <span class="keywordtype">void</span> onNewConnect(el::TcpConnect* connect);         <span class="comment">//收到新连接</span></div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    <span class="keywordtype">void</span> onClose(el::TcpConnect* connect);              <span class="comment">//关闭连接回调函数</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    <span class="keywordtype">void</span> error(el::TcpConnect* connect, <span class="keywordtype">int</span>);           <span class="comment">//发送错误回调函数</span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160; </div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160; </div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    <span class="keywordtype">int</span> response(<span class="keywordtype">char</span> *read_data,<span class="keywordtype">char</span> *send_data);          <span class="comment">//数据应答</span></div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    <span class="keywordtype">int</span> readData(<span class="keywordtype">char</span> *read_data,<span class="keywordtype">char</span> *send_data);          <span class="comment">//读数据应答</span></div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordtype">int</span> writeData(<span class="keywordtype">char</span> *read_data,<span class="keywordtype">char</span> *send_data);         <span class="comment">//写数据应答</span></div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160; </div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <span class="keywordtype">void</span> checkTimeOut();        <span class="comment">//连接超时时间检测</span></div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160; </div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    <span class="comment">//比较传入的IP地址是否为本地IP地址</span></div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    <span class="keywordtype">bool</span> checkLocalIP(<span class="keywordtype">char</span> *ip);</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160; </div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    el::TcpServer *server_;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    el::CommServer *manage;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160; </div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    <a class="code" href="struct_s_modbus_tcp_server_info.html">SModbusTcpServerInfo</a> server_info_;      <span class="comment">//通讯配置信息</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    <span class="keywordtype">string</span> ip_adress;</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160; </div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    <span class="comment">//默认前100给输入，后100给输出</span></div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;    <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> register_data_[MAX_SERVER_DATA_LEN];</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160; </div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    R_TRIG rTrigEnb;                        <span class="comment">//通讯开启上升沿</span></div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    F_TRIG fTrigEnb;                        <span class="comment">//通讯使能下降沿</span></div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160; </div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <a class="code" href="struct_s_tcp_connect_client_info.html">STcpConnectClientInfo</a> temp_info;</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    vector&lt;STcpConnectClientInfo&gt; client_list;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160; </div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;};</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160; </div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160; </div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160; </div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;<span class="preprocessor">#endif</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="astruct_s_tcp_connect_client_info_html"><div class="ttname"><a href="struct_s_tcp_connect_client_info.html">STcpConnectClientInfo</a></div><div class="ttdoc">TCP服务端连接列表</div><div class="ttdef"><b>Definition:</b> comm_struct_define.h:159</div></div>
<div class="ttc" id="acomm__struct__define_8h_html"><div class="ttname"><a href="comm__struct__define_8h.html">comm_struct_define.h</a></div><div class="ttdoc">通讯相关结构体定义</div></div>
<div class="ttc" id="aclass_modbus_tcp_server_html"><div class="ttname"><a href="class_modbus_tcp_server.html">ModbusTcpServer</a></div><div class="ttdef"><b>Definition:</b> modbustcp_server.h:35</div></div>
<div class="ttc" id="astruct_s_modbus_tcp_server_info_html"><div class="ttname"><a href="struct_s_modbus_tcp_server_info.html">SModbusTcpServerInfo</a></div><div class="ttdoc">ModbusTCP服务端配置参数</div><div class="ttdef"><b>Definition:</b> comm_struct_define.h:124</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
